/*
题目链接：https://leetcode.cn/problems/delete-and-earn/description/
	刘沛民	2024-12-3
*/

class Solution {
public:
    int deleteAndEarn(vector<int>& nums) {
        vector <int> bin(10e4, 0);         int n = nums.size();
        int a = 0; 
        for (int i = 0; i < n; i++)
        {
            bin[nums[i]]++;
            a = max(nums[i], a);
        }
        for (int i = 0; i <= a; i++)
        {
            bin[i] *= i;  
        }
        if (a <= 1)
        {
            int temp = 0;
            for (int i = 0; i <= a; i++)
            {
                temp = max(a, bin[i]);
            }
            return temp;
        }
        for (int i = 3; i <= a; i++)
        {
            bin[i] += max(bin[i - 2], bin[i - 3]);
        }
        return max(bin[a - 1], bin[a]);
    }
};
